
const userinfo = require("./src/userinfo.js")

class UserInfo {
  constructor (ctx){
    ctx = ctx || {};
    if (!ctx && !ctx.deployment) {
      throw new Error('deployment is need!');
    }
    this.deployment = ctx.deployment;
    this.context = ctx;
  }

  /**
   * @description: 存储用户信息
   * @param {object} obj.mix_userid 入参 必传
   * @return {object} 结果
   */
  async insert(obj){
    obj = obj || {};
    if (!obj && !obj.mix_userid) {
      return {
        success: false,
        data: {},
        errorCode: "422",
        errorMessage: "mix_userid must be needed!"
      }
    }

    return await userinfo.insert(this.context, obj);
  }

  /**
   * @description: 获取用户信息
   * @param {object} obj.mix_userid 入参 必传
   * @return {object} 结果
   */
  async get(obj){
    obj = obj || {};
    if (!obj && !obj.mix_userid) {
      return {
        success: false,
        data: {},
        errorCode: "422",
        errorMessage: "mix_userid must be needed!"
      }
    }
    return await userinfo.get(this.context, obj);
  }

  /**
   * @description: 存储用户自定义数据
   * @param {object} obj.mix_userid 入参 必传
   * @return {object} 结果
   */
  async insertKey(obj){
    obj = obj || {};
    if (!obj && !obj.mix_userid) {
      return {
        success: false,
        data: {},
        errorCode: "422",
        errorMessage: "mix_userid must be needed!"
      }
    }
    return await userinfo.insertKey( this.context, obj);
  }
}

module.exports = {
  UserInfo: UserInfo
}
